#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

bool is_prime(int x) {
	if (x <= 1)
		return false;
	for (int i = 2; i <= sqrt(x); ++i) {
		if (x % i == 0)
			return false;
	}
	return true;

}


void solve1() {
	int n;
	cin >> n;
	for (int i = 1; i <= (n - 2) / 2; ++i) {
		cout << 2 * i + 2 << "=";
		for (int j = 2; j <= i + 1; ++j) {
			if (is_prime(j) && is_prime(2 * i + 2 - j)) {
				cout << j << "+" << 2 * i + 2 - j << "\n";
				break;
			}
		}
	}


	return;
}


class student {
public:
	int a;
	int b;
	int c;

}s1;

void solve2() {
	int n;
	cin >> n;
	
	for (int i = 1; i <= n; ++i) {
		cin >> s1.a >> s1.b >> s1.c;
		if (s1.c + s1.b > 140 && (s1.c * 3 + s1.b * 7 >= 800)) {
			cout << "Excellent" << '\n';
		}
		else
			cout << "Not excellent" << '\n';
	}


	return;
}





class student1 {
public:
	string s;
	int a;
	int b;
	int c;

}s2[1010];


class cunchu {
public:
	string sb;
	string se;

}s3[1010];

bool cmp(cunchu s111, cunchu s222) {
	if (s111.sb < s222.sb) {
		return true;
	}
	if (s111.sb == s222.sb) {
		if (s111.se < s222.se)
			return true;
		else
			return false;


	}

	return false;
}

void solve3() {
	int n;
	cin >> n;
	

	for (int i = 1; i <= n; ++i) {
		cin >> s2[i].s >> s2[i].a >> s2[i].b >> s2[i].c;
	}
	for (int i = 1; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			
			if (abs(s2[i].a - s2[j].a) <= 5 && abs(s2[i].b - s2[j].b) <= 5 && abs(s2[i].c - s2[j].c) <= 5
				&& abs(s2[i].a + s2[i].b + s2[i].c - s2[j].a - s2[j].b - s2[j].c) <= 10) {
				
				cout << s2[i].s << " " << s2[j].s << endl;
		
				
			}
		}
	}
	/*sort(s3 + 1, s3 + n + 1, cmp);
	for (int i = 0; i <= 1009; ++i) {
		if (s3[i].sb == "" || s3[i].se == "")
			continue;
		cout << s3[i].sb << " " << s3[i].se << '\n';
	}*/


	return;
}

int main() {

	//solve1();
	//solve2();
	solve3();

	return 0;
}